<a href='https://github.com/angular/angular.js/edit/v1.4.x/src/Angular.js?message=docs(angular.forEach)%3A%20describe%20your%20change...#L217' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.4.7/src/Angular.js#L217' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">angular.forEach</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - function in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>Invokes the <code>iterator</code> function once for each item in <code>obj</code> collection, which can be either an
object or an array. The <code>iterator</code> function is invoked with <code>iterator(value, key, obj)</code>, where <code>value</code>
is the value of an object property or an array element, <code>key</code> is the object property key or
array element index and obj is the <code>obj</code> itself. Specifying a <code>context</code> for the function is optional.</p>
<p>It is worth noting that <code>.forEach</code> does not iterate over inherited properties because it filters
using the <code>hasOwnProperty</code> method.</p>
<p>Unlike ES262&#39;s
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18">Array.prototype.forEach</a>,
Providing &#39;undefined&#39; or &#39;null&#39; values for <code>obj</code> will not throw a TypeError, but rather just
return the value provided.</p>
<pre><code class="lang-js">var values = {name: &#39;misko&#39;, gender: &#39;male&#39;};
var log = [];
angular.forEach(values, function(value, key) {
  this.push(key + &#39;: &#39; + value);
}, log);
expect(log).toEqual([&#39;name: misko&#39;, &#39;gender: male&#39;]);
</code></pre>

</div>




<div>
  

    

  <h2 id="usage">Usage</h2>
    
      <p><code>angular.forEach(obj, iterator, [context]);</code></p>


    

    
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        obj
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-object">Object</a><a href="" class="label type-hint type-hint-array">Array</a>
      </td>
      <td>
        <p>Object to iterate over.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        iterator
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-function">Function</a>
      </td>
      <td>
        <p>Iterator function.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        context
        
        <div><em>(optional)</em></div>
      </td>
      <td>
        <a href="" class="label type-hint type-hint-object">Object</a>
      </td>
      <td>
        <p>Object to become context (<code>this</code>) for the iterator function.</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
    
    <h3>Returns</h3>
<table class="variables-matrix return-arguments">
  <tr>
    <td><a href="" class="label type-hint type-hint-object">Object</a><a href="" class="label type-hint type-hint-array">Array</a></td>
    <td><p>Reference to <code>obj</code>.</p>
</td>
  </tr>
</table>

  
  
  



  
</div>


